/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020-05-19 16:04
 */
package com.yao.sys.mapper.sql;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yao.sys.entity.dto.RoleDto;

import cn.hutool.core.util.StrUtil;

/**
 * 角色sql组装
 * 
 * @author yaoyuming
 * @date 2020/05/19 16:04
 */
public class RoleWrapper {

    /**
     * 功能描述 : 按名称查询
     * 
     * @param name
     * @author yaoyuming
     * @date 2020/4/14
     * @return {@link Wrapper < MenuDto>}
     */
    public static Wrapper<RoleDto> byName(String name) {
        LambdaQueryWrapper<RoleDto> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StrUtil.isNotEmpty(name), RoleDto::getName, name);
        return wrapper;
    }

    public static Wrapper<RoleDto> byKeys(String keys) {
        LambdaQueryWrapper<RoleDto> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StrUtil.isNotEmpty(keys), RoleDto::getKeys, keys);
        return wrapper;
    }

    public static Wrapper<RoleDto> byNameOrKeys(String name, String keys, Integer id) {
        LambdaQueryWrapper<RoleDto> wrapper = Wrappers.lambdaQuery();
        wrapper.and(null != id, i -> i.ne(RoleDto::getId, id));
        wrapper.and(i -> i.eq(StrUtil.isNotEmpty(keys), RoleDto::getKeys, keys).or()
                .eq(StrUtil.isNotEmpty(name), RoleDto::getName, name));

        return wrapper;
    }
}